package com.clean.notification.device;


import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.text.TextUtils;
import android.util.Log;

import com.clean.notification.BuildConfig;

/**
 * @author Admin
 */
public class LTRepositoryPhone {
    private static Context context;
    private static String version;
    private static String channel;
    public static String packageName;
    private static String appbiKey;
    private static volatile boolean hasInit;
    private static String versionCode;
    public static int API_LEVEL = 1;
    public static String mCountry;
    private static String srcAppName;

    public LTRepositoryPhone() {
    }


    public static void init(Context context, String appName) {
        hasInit = true;
        LTRepositoryPhone.context = context;
        try {
            srcAppName = appName;
            packageName = context.getPackageName();
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(packageName, 128);

            PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            version = pi.versionName;
            versionCode = String.valueOf(pi.versionCode);
            channel = "googleplay";
        } catch (Exception var42) {
            var42.printStackTrace();
        }

    }

    public static Context getContext() {
        return context;
    }

    public static String getVersion() {
        checkInit();
        if (TextUtils.isEmpty(version)) {
            try {
                PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
                version = pi.versionName;
            } catch (Exception var42) {
                var42.printStackTrace();
            }
            if (TextUtils.isEmpty(version)) {
                return "unknown";
            }
        }

        return version;
    }


    public static String getVersionCode() {
        checkInit();
        return versionCode;
    }

    public static String getChannel() {
        checkInit();
        Log.d("motao", channel);
        return channel;
    }

    public static String getPackageName() {
        return packageName;
    }

    public static String getAppName() {
        return srcAppName;
    }


    private static void checkInit() {
        if (BuildConfig.DEBUG && !hasInit) {
            throw new RuntimeException("channel has not initialized");
        }
    }
    public static String getCountry() {
        if (!TextUtils.isEmpty(mCountry)) {
            return mCountry;
        } else {
            mCountry = CountryManagerPhone.getInstance().getCountry();
            return mCountry;
        }
    }
    public static boolean getIsVpn() {
        return false;
    }
}
